package com.tojabo.swing.seven_listener;

import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class WindowAdapterDemo1 extends JFrame {
	public WindowAdapterDemo1() {
		super.setTitle("测试窗口");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		WindowListener wh = new windowhandler();
		addWindowListener(wh);
	}

	public static void main(String[] args) {
		WindowAdapterDemo1 me = new WindowAdapterDemo1();
		me.setSize(400, 300);
		me.setVisible(true);
	}

	class windowhandler extends WindowAdapter {
		public void windowClosing(WindowEvent e) {
			JButton b1 = new JButton("确定");
			JButton b2 = new JButton("取消");
			JLabel l = new JLabel("你能确定关闭系统了吗？");
			JDialog d = new JDialog((JFrame) e.getSource(), "系统出错了!", true);// 创建一个对话框
			d.setSize(200, 100);
			d.setLocation(0, 0);
			JPanel p = new JPanel();
			p.setLayout(new GridLayout(1, 2));
			d.add(p, "South");
			d.add(l, "Center");
			p.add(b1);
			p.add(b2);
			d.setVisible(true);
			b1.setVisible(true);
			b2.setVisible(true);
			l.setVisible(true);

		}
	}
}
